package edu.hitwh.service;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import edu.hitwh.entity.Borrower;
import edu.hitwh.entity.Librarian;
import edu.hitwh.respository.BorrowerRepository;
import edu.hitwh.respository.LibrarianRepository;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class RegisterService {
    private final LibrarianRepository librarianRepository;
    private final BorrowerRepository borrowerRepository;
    private final PasswordEncoder passwordEncoder;

    public Librarian registerLibrarian(Librarian librarian) {
        librarian.setPassword(passwordEncoder.encode(librarian.getPassword()));
        return librarianRepository.save(librarian);
    }

    public Borrower registerBorrower(Borrower borrower) {
        borrower.setPassword(passwordEncoder.encode(borrower.getPassword()));
        return borrowerRepository.save(borrower);
    }
}
